<?php
declare(strict_types=1);
namespace App\Pages;
use App\Controller;
use Field\SysApiStatRow;
use Field\SysCateConst;
use Field\SysPagesConst;

// hook controller_pages_index_use.php

/**
 * @title   单页
 * @auth    true
 * @rank    10
 */
class Index extends Controller
{
    // hook controller_pages_index_public_start.php

    // hook controller_pages_index_public_end.php
    protected string $name = '';
    /**
     * @title   单页列表
     * @rank    99
     */
    public function action_Help()
    {
        $this->name = '/help';
        return  $this->action_Index();
    }
    /**
     * @title   单页列表
     * @rank    99
     */
    public function action_Index()
    {
        // hook controller_pages_index_index_start.php
        $catePinyin = '/'.$this->request->param('name', '');
        !empty($this->name) && $catePinyin = $this->name;
        $page = $this->request->param('page', 1);
        $title = [];
        $cond = [];
        $path = '/';
        if (!empty($catePinyin) && empty($this->SysCate->DataPinyin[$catePinyin])) {
            $this->response('0301', [], '分类不存在', '/', 301);
        }
        $DataCate = $this->SysCate->DataKey[$this->SysCate->DataPinyin[$catePinyin]];
        $path = $catePinyin;

        if (!empty($this->SysCate->DataSon[$DataCate['CateID']])) {
            $CateIDs = $this->SysCate->DataSon[$DataCate['CateID']];
            $CateIDs[] = $DataCate['CateID'];
            $cond[SysPagesConst::CateID] = $CateIDs;
        } else {
            $cond[SysPagesConst::CateID] = $DataCate['CateID'];
        }
        $title[] = $DataCate['Name'];
        $orderby = [SysPagesConst::PageID => -1];
        $List = $this->SysPages->GetList($cond, $orderby, $page, 20);
        $page > 1 && $title[] = '第' . $page . '页';
        $List['total'] = 10000;
        $pagination = pagination("{$path}/{page}", $List['total'], $page, 20);
        // hook controller_pages_index_index_end.php
        return $this->View(get_defined_vars(),'@Index.Index');
    }

    /**
     * @title   单页详情
     * @rank    99
     */
    public function action_Detail()
    {

        return $this->View(get_defined_vars());
    }

    /**
     * @title   Doc文档
     * @rank    99
     */
    public function action_Doc()
    {
        $name = $this->request->param('name','');
        $DataCate = $this->SysCate->DataGroup['docs'];
        $RootCate = reset($DataCate);
        return $this->View(get_defined_vars());
    }

    /**
     * @title   单页DOC文档内容
     * @rank    99
     */
    public function action_Docs()
    {
        // hook controller_pages_index_docs_start.php
        $catePinyin = $this->request->param('name', '');
        $DataCate = $this->SysCate->DataGroup['docs'];
        $RootCate = reset($DataCate);
        $keyCate = arrlist_change_key($RootCate['children'], SysCateConst::Pinyin);
        $path = '/docs';
        if(!empty($catePinyin) && empty($keyCate[$catePinyin])){
            $this->response('0301',[],'分类不存在','/docs',301);
        }
        $CurrentCate=!empty($keyCate[$catePinyin]) ? $keyCate[$catePinyin] : [];
        // hook controller_pages_index_docs_end.php
        return $this->View(get_defined_vars());
    }

    /**
     * @title   单页服务条款
     * @rank    99
     */
    public function action_Terms()
    {
        return $this->View(get_defined_vars());
    }


    /**
     * @title   关于我们
     * @rank    99
     */
    public function action_About()
    {
        $this->name = '/about';
        return $this->View(get_defined_vars());
    }

    /**
     * @title   联系我们
     * @rank    99
     */
    public function action_Contact()
    {
        $this->name = '/contact';
        return $this->View(get_defined_vars());
    }
    // hook controller_pages_index_end.php
}
?>